package 复习.面试TOP101.链表;

public class 链表内指定区间反转 {
    public ListNode reverseBetween (ListNode head, int m, int n) {
        // write code here
        ListNode node = new ListNode(-1);
        ListNode cur = head;
        node.next = head;
        ListNode pre = node;
        for(int i = 1;i < m;i++){
            pre = cur;
            cur = cur.next;
        }
        while(m++ < n){
            ListNode temp = cur.next;
            cur.next = temp.next;
            temp.next = pre.next;
            pre.next = temp;
        }
        return node.next;
    }
}
